//
//  DoneGoodsViewController.m
//  Scanner
//
//  Created by 米明 on 15/6/13.
//  Copyright (c) 2015年 米明. All rights reserved.
//

#import "DoneGoodsViewController.h"
#import "CoreDataManager.h"
#import "GoodDetailViewController.h"
@interface DoneGoodsViewController ()
@property(nonatomic,retain)NSMutableArray * goodsArr;
@end

@implementation DoneGoodsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getRecents];
    [self creatRightBtnItemWithTitle:@"清空"];
    // Do any additional setup after loading the view.
}
-(void)rightBarBtnItem{
    [self clear];
}
-(void)clear{
    [[CoreDataManager shareManager]clearGoods];
    [self getRecents];
}
-(void)getRecents{
    
    _goodsArr=  [[CoreDataManager shareManager]goodsList];
    
    [self.tableView reloadData];
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _goodsArr.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString * cellID=@"cell";
    UITableViewCell * cell=[tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    Goods * goods=_goodsArr[indexPath.row];
    cell.textLabel.text=[goods name];
    cell.detailTextLabel.text=[goods code];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    Goods * goods=_goodsArr[indexPath.row];
    GoodDetailViewController * det = [[GoodDetailViewController alloc]init];
    det.title = goods.name;
    det.goodCode=goods.code;
    [self.navigationController pushViewController:det animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
